// CoffeeShop.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CoffeeShop {
    private List<Coffee> menu;
    private List<Order> orders;
    private Map<String, Customer> customers;
    private List<Payment> availablePayments;
    
    public CoffeeShop() {
        this.menu = new ArrayList<>(); // 单列集合
        this.orders = new ArrayList<>();
        this.customers = new HashMap<>();
        this.availablePayments = new ArrayList<>();
        
        initializeMenu();
        initializePayments();
    }
    
    private void initializeMenu() {
        menu.add(new Coffee("元宇宙拿铁", 32.0, "虚拟与现实的完美融合", 20));
        menu.add(new Coffee("哈希焦糖玛奇朵", 36.0, "区块链技术加持", 25));
        menu.add(new Coffee("二进制冰美式", 28.0, "极简主义代表", 15));
        menu.add(new Coffee("递归卡布奇诺", 34.0, "无限自我调用的美味", 30));
        menu.add(new Coffee("量子泡沫奶茶", 38.0, "多重宇宙风味", 35));
        menu.add(new Coffee("递", 34.0, "无限自的美味", 30));
        menu.add(new Coffee("量茶", 38.0, "风味", 35));

    }
    
    private void initializePayments() {
        availablePayments.add(new AlipayPayment());
        availablePayments.add(new CreditCardPayment("1234-5678-9012-3456", "12/25"));
        availablePayments.add(new CryptoPayment("0x742d35Cc6634C893292"));
    }
    
    // 添加顾客到系统
    public void addCustomer(Customer customer) {
        customers.put(customer.getName(), customer);
    }
    
    // 根据名字查找顾客
    public Customer findCustomer(String name) {
        return customers.get(name);
    }
    
    // 添加订单
    public void addOrder(Order order) {
        orders.add(order);
    }
    
    // 获取菜单
    public List<Coffee> getMenu() {
        return new ArrayList<>(menu); // 返回副本以避免外部修改
    }
    
    // 获取支付方式
    public List<Payment> getPaymentMethods() {
        return new ArrayList<>(availablePayments);
    }
    
    // 获取订单历史
    public List<Order> getOrderHistory() {
        return new ArrayList<>(orders);
    }
    
    // 根据顾客获取订单
    public List<Order> getOrdersByCustomer(String customerName) {
        List<Order> result = new ArrayList<>();
        for (Order order : orders) {
            if (order.getCustomer().getName().equals(customerName)) {
                result.add(order);
            }
        }
        return result;
    }
    
    // 获取顾客Map
    public Map<String, Customer> getCustomersMap() {
        return customers;
    }
    
    // 获取订单List
    public List<Order> getOrders() {
        return orders;
    }
    
    // 获取顾客（修复方法名）
    public Customer getCustomer(String name) {
        return customers.get(name);
    }
}